/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uloha4.controller;

import uloha4.entities.Node;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Point2D;
import uloha4.view.MagicCanvas;

/**
 *
 * @author Tomique
 */
public class TranslateController implements MouseListener, MouseMotionListener {

    // udava zmenu v jednotlivych souradnicich od posledniho eventu
    private int offsetX;
    private int offsetY;
    private MagicCanvas canvas;

    public TranslateController() {
        canvas = MagicCanvas.getInstance();
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // zaznamenam souradnice bodu, kde doslo k udalosti kliknuti mysi
        // (pocatek translace)
        offsetX = e.getX();
        offsetY = e.getY();
    }

    @Override
    public void mouseDragged(MouseEvent e) {

        // soucasna pozice kurzoru mysi
        int currentX = e.getX();
        int currentY = e.getY();

        // nova pozice, na kterou je treba presunout canvas
        int newX = currentX - offsetX;
        int newY = currentY - offsetY;

        // premisteni samotneho canvasu
        canvas.addTranslateX(newX);
        canvas.addTranslateY(newY);

        // offset se od posledni pozice zmenil, je treba ho proto updatovat
        offsetX += newX;
        offsetY += newY;

        // canvas prekreslim
        canvas.repaint();
    }

    @Override
    public void mouseClicked(MouseEvent e) {      
        canvas.markNode();
        canvas.repaint();
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }
}
